﻿<Page
    x:Class="ProximityExample.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ProximityExample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:data="using:ProximityExample.Data"
    xmlns:common="using:ProximityExample.Common"
    mc:Ignorable="d">
    <Page.Resources>
        <common:BoolVisibilityConverter x:Key="Show" />
        <data:ViewModel x:Key="ViewModel"/>
    </Page.Resources>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button Margin="39,59,39,0"
                    Style="{StaticResource NavigationBackButtonNormalStyle}"
                    VerticalAlignment="Top"
                    Visibility="Collapsed" />
            <TextBlock Text="Proximity Example" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
                       IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40" />
        </Grid>
        <Grid DataContext="{StaticResource ViewModel}" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="3">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Proximity Device:" Style="{StaticResource BaseTextBlockStyle}"/>
                <TextBlock Text="Found"
                           Visibility="{Binding HasProximityDevice, Converter={StaticResource Show}}"
                           Style="{StaticResource BaseTextBlockStyle}"
                           Margin="10 0 0 0" />
                <TextBlock Text="None"
                           Visibility="{Binding HasProximityDevice, Converter={StaticResource Show}, ConverterParameter='reverse'}"
                           Style="{StaticResource BaseTextBlockStyle}" Margin="10 0 0 0" />
                <TextBlock Text="Trigger:" Style="{StaticResource BaseTextBlockStyle}" Margin="10 0 0 0" />
                <TextBlock Text="Supported"
                           Visibility="{Binding SupportsTriggeredConnect, Converter={StaticResource Show}}"
                           Style="{StaticResource BaseTextBlockStyle}"
                           Margin="10 0 0 0" />
                <TextBlock Text="Not Supported"
                           Visibility="{Binding SupportsTriggeredConnect, Converter={StaticResource Show}, ConverterParameter='reverse'}"
                           Style="{StaticResource BaseTextBlockStyle}" Margin="10 0 0 0" />
                <TextBlock Text="Browse:" Style="{StaticResource BaseTextBlockStyle}" Margin="20 0 0 0" />
                <TextBlock Text="Supported"
                           Visibility="{Binding SupportsBrowseConnect, Converter={StaticResource Show}}"
                           Style="{StaticResource BaseTextBlockStyle}"
                           Margin="10 0 0 0" />
                <TextBlock Text="Not Supported"
                           Visibility="{Binding SupportsBrowseConnect, Converter={StaticResource Show}, ConverterParameter='reverse'}"
                           Style="{StaticResource BaseTextBlockStyle}" Margin="10 0 0 0" />
                <TextBlock Text="Connected Peer:" Style="{StaticResource BaseTextBlockStyle}" Margin="20 0 0 0" />
                <TextBlock Text="{Binding ConnectedPeer, FallbackValue='None'}"
                           Style="{StaticResource BaseTextBlockStyle}"
                           Margin="10 0 0 0" />
            </StackPanel>
            <StackPanel Grid.Row="1" Orientation="Horizontal">
                <Button Content="Start Advertising" Command="{Binding StartAdvertising}" />
                <Button Content="Stop Advertising" Command="{Binding StopAdvertising}" />
                <Button Content="Browse" Command="{Binding Browse}" Margin="10 0 0 0"/>
                <Button Content="Connect" Command="{Binding Connect}" Margin="10 0 0 0"/>
            </StackPanel>
            <StackPanel Grid.Row="2" Orientation="Horizontal">
                <TextBox Text="{Binding MessageToSend, Mode=TwoWay}" Width="300"/>
                <Button Content="Send" Command="{Binding SendMessage}"/>
                <TextBlock Text="Last Message: " Style="{StaticResource BaseTextBlockStyle}" Margin="20 0 0 0"/>
                <TextBlock TextWrapping="Wrap" Style="{StaticResource BaseTextBlockStyle}" Text="{Binding LastMessage}" Margin="10 0 0 0"/>
            </StackPanel>
            <TextBlock Grid.Row="3" Text="{Binding ErrorMessage}" Style="{StaticResource BaseTextBlockStyle}" FontWeight="Bold" Foreground="Red"/>
            <StackPanel Grid.Row="4" Orientation="Horizontal">
                <TextBlock Text="Selected Peer:" Style="{StaticResource BaseTextBlockStyle}"/>
                <TextBlock Text="{Binding SelectedPeer.Name, FallbackValue='None'}" Margin="10 0 0 0" Style="{StaticResource BaseTextBlockStyle}"/>
            </StackPanel>
            <ListView Grid.Row="5" ItemsSource="{Binding Peers}" SelectedItem="{Binding SelectedPeer, Mode=TwoWay}">
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Horizontal"></StackPanel>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <Grid Width="200" Height="100" Background="{StaticResource AppBarBackgroundThemeBrush}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <TextBlock Margin="5" Text="{Binding Name}" Style="{StaticResource BaseTextBlockStyle}" TextTrimming="CharacterEllipsis"/>
                            <TextBlock Margin="5" Grid.Row="1" Text="{Binding Text}" Style="{StaticResource CaptionTextBlockStyle}" TextWrapping="Wrap"></TextBlock>
                        </Grid>                        
                    </DataTemplate>                    
                </ListView.ItemTemplate>
            </ListView>
        </Grid>
    </Grid>
</Page>